﻿Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Partial Public Class WindowButton
    Inherits Button

#Region "DependencyProperties"

    ''' <summary>
    ''' Button content
    ''' <remarks>Base button's content property is hidden</remarks>
    ''' </summary>
    Public Shadows Property Content() As Object
        Get
            Return GetValue(ContentProperty)
        End Get
        Set(ByVal value As Object)
            SetValue(ContentProperty, value)
            RefreshContent()
        End Set
    End Property

    Public Shared Shadows ReadOnly ContentProperty As DependencyProperty = DependencyProperty.Register("Content", GetType(Object), GetType(WindowButton), New UIPropertyMetadata())

    ''' <summary>
    ''' Disabled button content
    ''' </summary>
    Public Property ContentDisabled() As Object
        Get
            Return GetValue(ContentDisabledProperty)
        End Get
        Set(ByVal value As Object)
            SetValue(ContentDisabledProperty, value)
            RefreshContent()
        End Set
    End Property

    Public Shared ReadOnly ContentDisabledProperty As DependencyProperty = DependencyProperty.Register("ContentDisabled", GetType(Object), GetType(WindowButton), New UIPropertyMetadata())

    ''' <summary>
    ''' Corner radius of the button
    ''' </summary>
    Public Property CornerRadius() As CornerRadius
        Get
            Return DirectCast(GetValue(CornerRadiusDPProperty), CornerRadius)
        End Get
        Set(ByVal value As CornerRadius)
            SetValue(CornerRadiusDPProperty, value)
        End Set
    End Property

    Public Shared ReadOnly CornerRadiusDPProperty As DependencyProperty = DependencyProperty.Register("CornerRadius", GetType(CornerRadius), GetType(WindowButton), New UIPropertyMetadata(New CornerRadius()))


    <System.ComponentModel.Bindable(True)> _
    Public Property ActiveContent() As Object
        Get
            Return GetValue(ActiveContentProperty)
        End Get
        Set(ByVal value As Object)
            SetValue(ActiveContentProperty, value)
        End Set
    End Property
    Public Shared ReadOnly ActiveContentProperty As DependencyProperty = DependencyProperty.Register("ActiveContent", GetType(Object), GetType(WindowButton), New UIPropertyMetadata())

#End Region

    ''' <summary>
    ''' Arrière plan par défaut du bouton 
    ''' </summary>
    Public Overridable ReadOnly Property BackgroundDefaultValue() As Brush
        Get
            Return DirectCast(FindResource("DefaultBackgroundBrush"), Brush)
        End Get
    End Property

    ''' <summary>
    ''' Constructeur
    ''' </summary>
    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub WindowButton_IsEnabledChanged(ByVal sender As Object, ByVal e As System.Windows.DependencyPropertyChangedEventArgs) Handles Me.IsEnabledChanged
        RefreshContent()
    End Sub
    ''' <summary>
    ''' Met à jour le contenu du bouton en fonction de la valeur courante de la propriété "isEnabled"
    ''' </summary>
    Protected Sub RefreshContent()
        ' Button is enabled
        If Me.IsEnabled Then
            Me.ActiveContent = Me.Content
        Else
            Me.ActiveContent = Me.ContentDisabled
        End If
    End Sub

End Class